// Agent Ecomp
!decidetarget.

+?pos(X, Y, S)
  <- .print("get position");
     .wait({+pos(X,Y,S)}).
  
+?gsize(W,H)
  <- .wait({+gsize(W,H)}).

+!decidetarget
  : cow (_,X,Y)
  <- .print("I'm looking to a COW!!!");
     -+target(X,Y).

+!decidetarget
  : true
  <- ?pos(OX,OY,_);
  	 .print("decide Target");
     jia.random2(OX,OY,NX,NY); 
     -+target(NX,NY).
  
+target(NX,NY)
  :  not jia.obstacle(NX,NY) &
     not jia.fence(NX,NY) &
     not jia.corral(NX,NY)  
  <- .print("defining target");
  	 .drop_desire(move);
     jia.set_target(NX,NY); 
     !!move.
 +target(X,Y)
 	:	cow (_,X,Y)
 	<-	.print("COW COW COW!!");
 	-+target(X,Y).
 	
+target(NX,NY)
  : true
  <- !decidetarget. 
+!move
  :  pos(X,Y,_) &
     target(X,Y)
  <- !decidetarget.
+!move 
   : pos(X,Y,_) & 
     target(BX,BY) & 
     jia.direction(X, Y, BX, BY, D) // jia.direction finds one action D (using A*) towards the target
   <- .print("move...");
   	  do(D);  // this action will "block" the intention until it is sent to the simulator (in the end of the cycle)
      !!move. // continue moving
  
/*
*  Restarting Achievments  
*/

// The agent is whaiting for another pass_fence scheme to be accomplished. 
+!restart
 :	not .intend(restart) &
 	.my_name(Me) &  
    scheme_group(Sch,_) &
    scheme(pass_fence_sch,Sch)
 <- .print("[usp.asl] I'm in another pass_fence scheme, shouldn't restart").

// Here, if I'm not commited to something, then.. I should restart.
+!restart
 : 	not .intend(restart) &
 	.my_name(Me) &
 	not commitment(Me,_,_)
 <- .print("[usp.asl] Restarting agent!");
 	!decidetarget.

// finally, if i'm commited to something, then, don't restart.
+!restart
<- .print("not restarting").

